//
//  AuctionInfoVehiclePics.m
//
//  Created by lizhenqiang  on 15/8/9
//  Copyright (c) 2015 __MyCompanyName__. All rights reserved.
//

#import "AuctionInfoVehiclePics.h"


NSString *const kAuctionInfoVehiclePicsVehicleId = @"vehicleId";
NSString *const kAuctionInfoVehiclePicsId = @"id";
NSString *const kAuctionInfoVehiclePicsTradId = @"tradId";
NSString *const kAuctionInfoVehiclePicsSmallPicUrl = @"smallPicUrl";
NSString *const kAuctionInfoVehiclePicsShowOrder = @"showOrder";
NSString *const kAuctionInfoVehiclePicsPicUrl = @"picUrl";


@interface AuctionInfoVehiclePics ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation AuctionInfoVehiclePics

@synthesize vehicleId = _vehicleId;
@synthesize vehiclePicsIdentifier = _vehiclePicsIdentifier;
@synthesize tradId = _tradId;
@synthesize smallPicUrl = _smallPicUrl;
@synthesize showOrder = _showOrder;
@synthesize picUrl = _picUrl;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.vehicleId = [[self objectOrNilForKey:kAuctionInfoVehiclePicsVehicleId fromDictionary:dict] doubleValue];
            self.vehiclePicsIdentifier = [[self objectOrNilForKey:kAuctionInfoVehiclePicsId fromDictionary:dict] doubleValue];
            self.tradId = [[self objectOrNilForKey:kAuctionInfoVehiclePicsTradId fromDictionary:dict] doubleValue];
            self.smallPicUrl = [self objectOrNilForKey:kAuctionInfoVehiclePicsSmallPicUrl fromDictionary:dict];
            self.showOrder = [[self objectOrNilForKey:kAuctionInfoVehiclePicsShowOrder fromDictionary:dict] doubleValue];
            self.picUrl = [self objectOrNilForKey:kAuctionInfoVehiclePicsPicUrl fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.vehicleId] forKey:kAuctionInfoVehiclePicsVehicleId];
    [mutableDict setValue:[NSNumber numberWithDouble:self.vehiclePicsIdentifier] forKey:kAuctionInfoVehiclePicsId];
    [mutableDict setValue:[NSNumber numberWithDouble:self.tradId] forKey:kAuctionInfoVehiclePicsTradId];
    [mutableDict setValue:self.smallPicUrl forKey:kAuctionInfoVehiclePicsSmallPicUrl];
    [mutableDict setValue:[NSNumber numberWithDouble:self.showOrder] forKey:kAuctionInfoVehiclePicsShowOrder];
    [mutableDict setValue:self.picUrl forKey:kAuctionInfoVehiclePicsPicUrl];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.vehicleId = [aDecoder decodeDoubleForKey:kAuctionInfoVehiclePicsVehicleId];
    self.vehiclePicsIdentifier = [aDecoder decodeDoubleForKey:kAuctionInfoVehiclePicsId];
    self.tradId = [aDecoder decodeDoubleForKey:kAuctionInfoVehiclePicsTradId];
    self.smallPicUrl = [aDecoder decodeObjectForKey:kAuctionInfoVehiclePicsSmallPicUrl];
    self.showOrder = [aDecoder decodeDoubleForKey:kAuctionInfoVehiclePicsShowOrder];
    self.picUrl = [aDecoder decodeObjectForKey:kAuctionInfoVehiclePicsPicUrl];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeDouble:_vehicleId forKey:kAuctionInfoVehiclePicsVehicleId];
    [aCoder encodeDouble:_vehiclePicsIdentifier forKey:kAuctionInfoVehiclePicsId];
    [aCoder encodeDouble:_tradId forKey:kAuctionInfoVehiclePicsTradId];
    [aCoder encodeObject:_smallPicUrl forKey:kAuctionInfoVehiclePicsSmallPicUrl];
    [aCoder encodeDouble:_showOrder forKey:kAuctionInfoVehiclePicsShowOrder];
    [aCoder encodeObject:_picUrl forKey:kAuctionInfoVehiclePicsPicUrl];
}

- (id)copyWithZone:(NSZone *)zone
{
    AuctionInfoVehiclePics *copy = [[AuctionInfoVehiclePics alloc] init];
    
    if (copy) {

        copy.vehicleId = self.vehicleId;
        copy.vehiclePicsIdentifier = self.vehiclePicsIdentifier;
        copy.tradId = self.tradId;
        copy.smallPicUrl = [self.smallPicUrl copyWithZone:zone];
        copy.showOrder = self.showOrder;
        copy.picUrl = [self.picUrl copyWithZone:zone];
    }
    
    return copy;
}


@end
